{% extends "layouts/application.html" %}
{% block content %}

<script type="text/javascript">
  function pageselectCallback(page_id, jq){
    //alert(page_id)
    window.location.href="?page="+(page_id+1);
    }
    $(document).ready(function(){
    // Create pagination element
        $("#Pagination").pagination({{objects.paginator.count}}, {
      num_edge_entries: 2,
      num_display_entries: 8,
      current_page:({{objects.number}}-1),
            callback: pageselectCallback
        });
    });

	function isRePass(id){
		if(window.confirm('确认密码初始化？初始化后,密码为:000000')){
			location.href='/{%site_root%}/manage/re_password/'+id
		}
	}
	function checkForm(){
		var realName = $('input[@name=real_name]').fieldValue();
		var userName = $('input[@name=username]').fieldValue();
		if(!userName[0]){
			alert("登录不能为空！");
			return false;
		}
		if(!realName[0]){
			alert("真实姓名不能为空！");
			return false;
		}
		return true;
	}
</script>
<div align="center">
  <div class="boxright">
    <div class="bltop2">
      <div align="left">
        <strong>
          当前位置：&nbsp;&nbsp;
          <a href="/{%site_root%}/manage/index/">后台管理</a>&nbsp;&nbsp;
          <img src="/site_media/images/zd_arrow.gif">&nbsp;&nbsp;
          <a href="#">用户管理</a>
        </strong>
      </div>
    </div>
    <div class="rep_left_height">
        <div id="user_div">
          <form action="" method="post" onsubmit="return checkForm()">
            <TABLE id="tblSearch"  cellSpacing=0 cellPadding=4 width="100%" border=0>
              <TBODY>
                <TR>
                  <TD class=rep_li_c2 width="20%" ALIGN="left">登录名</TD>
                  <TD class=rep_li_c2 width="30%" ALIGN="left">
                     {{user_form.username}}{{user_form.username.errors}}
                  </TD>
                  <TD class=rep_li_c2 width="20%" ALIGN="left">真实姓名</TD>
                  <TD class=rep_li_c2 width="30%" ALIGN="left">
                    {{profile_form.real_name}}{{user_form.real_name.errors}}
                  </TD>
                </TR>
                <TR>
                  <TD class=rep_li_c2 ALIGN="left">单位</TD>
                  <TD class=rep_li_c2 ALIGN="left">
                    {{profile_form.department}}{{profile_form.department.errors}}
                  </TD>
                  <TD class=rep_li_c2 ALIGN="left">电话</TD>
                  <TD class=rep_li_c2 ALIGN="left">
                    {{profile_form.phone}}{{user_form.phone.errors}}
                  </TD>
                </TR>
                <TR>
                  <TD class=rep_li_c2 ALIGN="left">选择角色</TD>
                  <TD class=rep_li_c2 ALIGN="left">
                    {{user_form.groups}}{{user_form.groups.errors}}
                  </TD>
                  <TD class=rep_li_c2 style="color:green">用户默认初始密码为：000000</TD>
                  <TD class=rep_li_c2 ALIGN="left">&nbsp;</TD>
                </TR>
                <TR>
                  <TD class=rep_li_c2 colSpan=4>
                    {% if not obj %}
                    <INPUT ONCLICK="return onadd();"
                           onMouseOver="this.className='submit2'"
                           onMouseOut ="this.className='submit'"
                           class=submit
                           id="modify"
                           type=submit
                           value=添加 name="">
                     {% else %}
                    <INPUT ONCLICK="return onadd();"
                           onMouseOver="this.className='submit2'"
                           onMouseOut ="this.className='submit'"
                           class=submit
                           id="modify"
                           type=submit
                           value=保存 name="">
                     {% endif %}

                    <INPUT onMouseOver="this.className='reset2'"
                           onMouseOut="this.className='reset'"
                           id="btn8"
                           class="reset"
                           type="reset"
                           value=取消>
                  </TD>
                </TR>
              </TBODY>
            </TABLE>
          </form>
        </div>
        {% if objects %}
        <form action="/{%site_root%}/manage/edit_active/" method="post">
          <TABLE class=tatop7px cellSpacing=0 cellPadding=4 width="100%" border=0>
            <TBODY>
              <TR>
                <TD class=rtdw width="4%">
                  <INPUT id="chkAll" onclick="title_check('chkAll','chkID[]')"  type=checkbox value=checkbox>
                </TD>
                <TD class=rep_li_c width="18%"><STRONG>登录名</STRONG></TD>
                <TD class=rep_li_c width="18%"><STRONG>真实姓名</STRONG></TD>
                <TD class=rep_li_c width="10%"><STRONG>部门</STRONG></TD>
                <TD class=rep_li_c width="13%"><STRONG>电话</STRONG></TD>
                <TD class=rep_li_c width="10%"><STRONG>状态</STRONG></TD>
                <TD class=rep_li_c width="20%"><STRONG>隶属角色</STRONG></TD>
                <TD class=rep_li_c width="20%"><STRONG></STRONG></TD>
              </TR>
              <tr id="after_tr"></tr>
              {% for user in objects.object_list %}
                <TR id="tr_{{user.id}}" style="TEXT-DECORATION: none" onMouseOver="this.style.backgroundColor='#EFF8FF'" onmouseout="this.style.backgroundColor=''">
                  <TD class=rtdw2>
                  {% if not user.is_superuser %}
                  <INPUT onclick="rows_check('chkAll','chkID[]')" type=checkbox value="{{user.id}}" name="chkID[]"></TD>
                  {% endif %}
                  <TD class=rep_li_td_bt >&nbsp;
                    {% if not user.is_superuser %}
                    <A HREF="../edit_user/{{user.id}}" style="text-decoration:underline">{{user.username}}</A>
                    {% else %}
                    <A style="text-decoration:underline;color:red">{{user.username}}</A>
                    {% endif %}
                  </TD>
                  <TD class=rep_li_td_bt>&nbsp;{{user.profile.real_name}}</TD>
                  <TD class=rep_li_td_bt>&nbsp;{{user.profile.department}}</TD>
                  <TD class=rep_li_td_bt>&nbsp;{{user.profile.phone}}</TD>
                  <TD class=rep_li_td_bt>&nbsp;
                    {% if user.is_active %}启用
                    {% else %}禁用
                    {% endif %}
                  </TD>
                  <TD class=rep_li_td_bt>&nbsp;
                    {% if user.groups %}
                    {% for group in user.groups.all %}
                      {{group.name}}
                    {% endfor %}
                    {% endif %}
                  </TD>
                  <TD class=rep_li_td_bt>
                  <a href="javascript:isRePass({{user.id}})"><img alt="密码重置" src="/site_media/images/ico_modif_file.png" height="16" width="16" border="0"></a>
                  </TD>
                </TR>
              {% endfor %}

            </TBODY>
          </TABLE>


          <TABLE cellSpacing=0 cellPadding=4 width="100%" border=0>
            <TBODY>
              <TR vAlign="top" ALIGN="left">
                <TD>
                  <INPUT onclick="check_select('chkID[]')"
                         onMouseOver="this.className='bt1h'"  onMouseOut ="this.className='bt1'"
                         class="bt1" name="button" type="submit" value="启/禁用" id="use">
                  <INPUT onclick="check_select_one('chkAll','chkID[]')"
                         onMouseOver="this.className='topanniu2'"  onMouseOut ="this.className='topanniu'"
                         class="button" name="button" type="button" value="密码重置" id="setpass">
                </TD>
                <td>
                <div id="Pagination" class="pagination">
                </td>
              </TR>
            </TBODY>
          </TABLE>
        </form>
         {% endif %}
      </div>
  </div>
</div>
{% endblock %}
